<?php
	if(!isset($_REQUEST['ajax'])){ $_REQUEST['ajax'] = "";}
	if($_REQUEST['ajax']!=true) include 'header.tpl.php';
	//include 'project_panel.tpl.php';
?>
	<div class="row">
		<div class="col-lg-12">
			<ul class="shortcut-buttons-set">
				<li>
					<a class="shortcut-button" href='#project_view/pid=<?php echo $this->item['pId'];?>'><span>
					<i class="aicon-task_detail"></i>
					<?php echo $this->language['detail'];?></span></a>
				</li>
				<?php if(check_permission('project_salary_edit')): ?>
				<li>
					<a class="shortcut-button" href='#project_view/pid=<?php echo $this->item['pId'];?>&mod=salaries'><span>
					<i class="aicon-chietkhau"></i>
					Hoa hồng</span></a>
				</li>
				<?php endif;?>
				<?php if(check_permission('project_view') && $this->item['pParent'] == 0){ ?>
				<li>
					<a class="shortcut-button" href='#project_view/pid=<?php echo $this->item['pId'];?>&mod=bussiness'><span>
					<i class="aicon-chart"></i>
					<?php echo $this->language['bussiness'];?></span></a>
				</li>
				<?php }?>
				<?php if($this->item['pParent'] == 0):?>
				<li>
					<a class="shortcut-button" href='#project_create/pid=<?php echo $this->item['pId'];?>'><span>
					<i class="aicon-project_add"></i>
					Tạo dự án con</span></a>
				</li>
				<?php endif;?>
			</ul>
		</div>
	</div>
	<input type="hidden" id="pidhid" name="pidhid" value="<?php echo $this->item['pId'];?>">
	<div class="row">
		<div class="col-lg-5">
			<iframe frameborder="0" scrolling="no" height="400px" src="./ttg/report/views/panel.html?id=31&project_id=<?php echo $this->item['pId'];?>&frame"></iframe>
			<?php if($this->du_toan['dong_tien']):?>
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="icon-list"></i> Dòng tiền</div>
				</div>
				<div class="panel-body">
					<table class="table table-hover table-condensed">
						<thead>
							<tr>
								<th width="100px">Ngày thêm</th>
								<th width="100px">Số tiền</th>
								<th>Mô tả</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($this->item['pCreditReceived'] as $row):?>
							<tr>
								<td><?php echo date("d/m/Y",$row['date']);?></td>
								<td><?php echo number_format($row['amount'],0,'.',',');?></td>
								<td><?php echo nl2br($row['desc']);?></td>
							</tr>
							<?php endforeach; ?>
						</tbody>
					</table>
				</div>
			</div>
			<?php endif;?>
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="icon-list"></i> <?php echo $this->language['requests'];?></div>
				</div>
				<div class="panel-body">
					<?php if(count($this->requests) > 0){ ?>
					<table class="table table-hover table-condensed">
						<thead>
							<tr>
								<th>Lý do</th>
								<th width='110px'>Số tiền</th>
								<th width='120px'>Người tạo</th>
							</tr>
						</thead>
						<tbody>
					<?php foreach($this->requests as $row){ ?>
							<tr>
								<td><a href="#request_view/id=<?php echo $row['req_id'];?>"><?php echo $row['req_reason'];?></a></td>
								<td><?php echo number_format($row['amount'],0,'.',',');?></td>
								<td><a href="#user_view/uId=<?php echo $row['user_id'];?>"><?php echo $_SESSION['user_data'][$row['user_id']]['fullname'];?></a></td>
							</tr>
					<?php } ?>
						</tbody>
					</table>
					<?php }else{ ?>
					<div class="alert alert-danger">Không có phiếu tạm ứng nào</div>
					<?php } ?>
				</div>
			</div>
		</div>
		<div class="col-lg-7">
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="icon-list"></i> Thông tin Dự toán</div>
				</div>
				<div class="panel-body">
					<ul class="list-group">
						<li class="list-group-item">
							<b>Doanh thu thuần <a data-toggle="modal" data-target="#updateCredit">[Cập nhật]</a></b>
							<span class="pull-right"><?php echo number_format($this->du_toan['doanh_thu'],0,'.',',');?></span>
							<div class="clear"></div>
							<?php if(count($this->item['sub_projects']) > 0):?>
							<table class="table table-bordered table-striped table-condensed">
								<?php foreach($this->item['sub_projects'] as $row):?>
								<tr>
									<td><?php echo $row['pName'];?></td>
									<td><?php echo number_format($row['pCredit'],0,'.',',');?></td>
								</tr>
								<?php endforeach;?>
							</table>
							<div class="clear"></div>
							<?php endif;?>
						</li>
						<li class="list-group-item">
							<b>Doanh thu thực <a data-toggle="modal" data-target="#insertRevenue">[Thêm]</a></b>
							<span class="pull-right"><?php echo number_format($this->du_toan['dong_tien'],0,'.',',');?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b>Tổng lương hoa hồng</b>
							<span class="pull-right"><?php echo number_format($this->du_toan['luong_da_chia'],0,'.',',');?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b>Tổng tạm ứng</b>
							<span class="pull-right"><?php echo number_format($this->du_toan['tong_tam_ung'],0,'.',',');?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b>Tổng chi phí đối tác</b>
							<span class="pull-right"><a href="#" data-toggle='modal' data-target='#cost_list'><?php echo number_format($this->du_toan['tong_chi_phi'],0,'.',',');?></a></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b>Lợi nhuận</b>
							<span class="pull-right"><?php echo number_format($this->du_toan['loi_nhuan'],0,'.',',');?></span>
							<div class="clear"></div>
						</li>
					</ul>
				</div>
			</div>
			<div class="panel">
				<div class="panel-heading <?php echo ($this->item['pQToan']) ? 'green' : 'red';?>">
					<div class="panel-title">
						<i class="icon-list"></i> Thông tin Quyết toán
						<?php if(check_permission('project_salary_edit') && $this->item['pQToan'] == 0):?>
						<button class="btn btn-success" onClick="QToanToggle(<?php echo $this->item['pId'];?>);"><i class="icon-check"></i> Đánh dấu Quyết toán</button>
						<?php endif;?>
					</div>
				</div>
				<div class="panel-body">
					<ul class="list-group">
						<li class="list-group-item">
							<b>Tổng tiền Thu</b>
							<span class="pull-right">
								<?php
									echo "<a href='#' data-toggle='modal' data-target='#pay_thu_list'>".number_format($this->quyet_toan['total_thu'],0,'.',',')." (".$this->quyet_toan['count_thu'].")</a>";
								?>
							</span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b>Tổng phí VAT phiếu Thu</b>
							<span class="pull-right">
								<?php
									echo "<a href='#' data-toggle='modal' data-target='#pay_thu_vat_list'>".number_format($this->quyet_toan['total_thu_vat'],0,'.',',')." (".$this->quyet_toan['count_thu_vat'].")</a>";
								?>
							</span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b>Tổng tiền Chi</b>
							<span class="pull-right">
								<?php
									echo "<a href='#' data-toggle='modal' data-target='#pay_chi_list'>".number_format($this->quyet_toan['total_chi'],0,'.',',')." (".$this->quyet_toan['count_chi'].")</a>";
								?>
							</span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b>Tổng phí VAT phiếu Chi</b>
							<span class="pull-right">
								<?php
									echo "<a href='#' data-toggle='modal' data-target='#pay_chi_vat_list'>".number_format($this->quyet_toan['total_chi_vat'],0,'.',',')." (".$this->quyet_toan['count_chi_vat'].")</a>";
								?>
							</span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b>Tổng lương kỹ thuật</b>
							<span class="pull-right">
								<?php
									echo number_format($this->quyet_toan['tong_luong_ky_thuat'],0,'.',',');
								?>
							</span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b>Lợi nhuận</b>
							<span class="pull-right"><?php echo number_format($this->quyet_toan['loi_nhuan'],0,'.',',');?></span>
							<div class="clear"></div>
						</li>
					</ul>
				</div>
			</div>
		</div>
	</div>
	<?php if(count($this->technical) > 0):?>
	<div class="row">
		<div class="col-lg-12">
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="icon-cog"></i> Lương kỹ thuật</div>
				</div>
				<div class="panel-body">
					<table class="footable table table-hover table-condensed">
						<thead>
							<tr>
								<th data-toggle="true" width="150px">Họ tên</th>
								<th class="text-center">Nhóm trưởng</th>
								<th class="text-center">Chạy chính</th>
								<th class="text-center">Chạy phụ</th>
								<th class="text-center">Kỹ thuật</th>
								<th class="text-center">Tháo</th>
								<th class="text-center">Lắp</th>
								<th class="text-center">Show đêm</th>
								<th class="text-center" data-hide="phone,tablet">Tài xế</th>
								<th class="text-center" data-hide="phone,tablet">TX đi tỉnh</th>
								<th class="text-center" data-hide="phone,tablet">TX show đêm</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($this->technical as $row):?>
							<tr>
								<td>
									<?php if($row['tech_user_type'] == 'KTLED'): ?><a href="#user_view/uId=<?php echo $row['tech_user_id'];?>"><?php echo $row['tech_user_name'];?></a>
									<?php else: ?><?php echo $row['tech_user_name'];?>
									<?php endif;?>
								</td>
								<?php for($i = 1; $i <= 10; $i++):?>
								<td class="text-center">
									<?php
										echo ($row['salary'][$i]) ? number_format(($row['salary'][$i]),0,'.',',') : '-';
									?>
								</td>
								<?php endfor;?>
							</tr>
							<?php endforeach;?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<?php endif;?>
	<div class="modal fade" id="updateCredit">
		<div class="modal-dialog">
			<div class="modal-content">
				<form action="javascript:updateProject();">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title">Cập nhật Doanh thu thuần</h4>
					</div>
					<div class="modal-body">
						<fieldset>
							<div class="form-group">
								<label for="noteTitle">Số tiền</label>
								<input type="text" class="form-control" name="credit" id="update_credit" value="<?php echo number_format($this->du_toan['doanh_thu'],0,'.',',');?>" />
							</div>
						</fieldset>
					</div>
					<div class="modal-footer">
						<input type="submit" class="btn btn-primary" value="Đồng ý" />
					</div>
				</form>
			</div>
		</div>
	</div>
	<div class="modal fade" id="insertRevenue">
		<div class="modal-dialog">
			<div class="modal-content">
				<form action="javascript:insertRevenue();">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title">Thêm doanh thu thực</h4>
					</div>
					<div class="modal-body">
						<fieldset>
							<div class="form-group">
								<label for="noteTitle">Số tiền</label>
								<input type="text" class="form-control" name="amount" id="revenue_amount" placeholder="Số tiền" />
							</div>
							<div class="form-group">
								<label for="noteTitle">Mô tả</label>
								<textarea class="form-control" id="revenue_desc" placeholder="Mô tả"></textarea>
							</div>
						</fieldset>
					</div>
					<div class="modal-footer">
						<input type="submit" class="btn btn-primary" value="Đồng ý" />
					</div>
				</form>
			</div>
		</div>
	</div>
	<div class="modal fade" id="pay_thu_list" data-width='700px'>
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">Danh sách phiếu thu thuộc dự án</h4>
				</div>
				<div class="modal-body">
					<table class="table table-hover table-condensed">
						<thead>
							<tr>
								<th>Lý do</th>
								<th width='90px'>Số tiền</th>
								<th width='90px'>Ngày</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($this->payments as $row): if($row['pay_type'] == 1 && $row['pay_vat'] == 0):?>
							<tr>
								<td><a href="#finance_view/id=<?php echo $row['pay_id'];?>"><?php echo $row['pay_description'];?></a></td>
								<td><?php echo number_format($row['pay_amount'],0,'.',',');?></td>
								<td><?php echo date("d/m/Y",$row['pay_date']);?></td>
							</tr>
							<?php endif;endforeach;?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="pay_thu_vat_list" data-width='700px'>
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">Danh sách phí VAT phiếu thu</h4>
				</div>
				<div class="modal-body">
					<table class="table table-hover table-condensed">
						<thead>
							<tr>
								<th>Lý do</th>
								<th width='90px'>Số tiền</th>
								<th width='90px'>Ngày</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($this->payments as $row): if($row['pay_type'] == 1 && $row['pay_vat'] == 1):?>
							<tr>
								<td><a href="#finance_view/id=<?php echo $row['pay_id'];?>"><?php echo $row['pay_description'];?></a></td>
								<td><?php echo number_format($row['pay_amount'],0,'.',',');?></td>
								<td><?php echo date("d/m/Y",$row['pay_date']);?></td>
							</tr>
							<?php endif;endforeach;?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="pay_chi_list" data-width='700px'>
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">Danh sách phiếu chi thuộc dự án</h4>
				</div>
				<div class="modal-body">
					<table class="table table-hover table-condensed">
						<thead>
							<tr>
								<th>Lý do</th>
								<th width='90px'>Số tiền</th>
								<th width='90px'>Ngày</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($this->payments as $row): if($row['pay_type'] == 0):?>
							<tr>
								<td><a href="#finance_view/id=<?php echo $row['pay_id'];?>"><?php echo $row['pay_description'];?></a></td>
								<td><?php echo number_format($row['pay_amount'],0,'.',',');?></td>
								<td><?php echo date("d/m/Y",$row['pay_date']);?></td>
							</tr>
							<?php endif;endforeach;?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="pay_chi_vat_list" data-width='700px'>
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">Danh sách phí VAT phiếu chi</h4>
				</div>
				<div class="modal-body">
					<table class="table table-hover table-condensed">
						<thead>
							<tr>
								<th>Lý do</th>
								<th width='90px'>Số tiền</th>
								<th width='90px'>Ngày</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($this->payments as $row): if($row['pay_type'] == 0 && $row['pay_vat'] == 1):?>
							<tr>
								<td><a href="#finance_view/id=<?php echo $row['pay_id'];?>"><?php echo $row['pay_description'];?></a></td>
								<td><?php echo number_format($row['pay_amount'],0,'.',',');?></td>
								<td><?php echo date("d/m/Y",$row['pay_date']);?></td>
							</tr>
							<?php endif;endforeach;?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>

	<div class="modal fade" id="cost_list" data-width='700px'>
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">Danh sách chi phí</h4>
				</div>
				<div class="modal-body">
					<table class="table table-hover table-condensed">
						<thead>
							<tr>
								<th>Người tạo</th>
								<th>Lý do</th>
								<th width='90px'>Số tiền</th>
								<th width='90px'>Ngày</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($this->costs as $row):?>
							<tr>
								<td><a href="#user_view/uId=<?php echo $row['uId'];?>"><?php echo $_SESSION['user_data'][$row['uId']]['fullname'];?></a></td>
								<td><a href="#cost_view/id=<?php echo $row['cost_id'];?>"><?php echo $row['cost_reason'];?></a></td>
								<td><?php echo number_format($row['cost_total'],0,'.',',');?></td>
								<td><?php echo date("d/m/Y",$row['cost_create_date']);?></td>
							</tr>
							<?php endforeach;?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
<?php if(isset($this->breadcrumb) && isset($this->title_header)):?>
	<script type="text/javascript">
		$(function() {
			$("#title-header").text('<?php echo $this->title_header;?>');
			$("#breadcrumb").html('<?php echo build_breadcrumb($this->breadcrumb);?>');
		});
	</script>
<?php endif;?>
<?php
	if($_REQUEST['ajax']!=true) include 'footer.tpl.php';
?>